<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
	String path = request.getContextPath() + "/";
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
<title>朗读亭——素材管理</title>
<!-- Tell the browser to be responsive to screen width -->
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
</head>
<body>
	<section class="content-header">
      <h1>
        系统管理
        <small>素材管理</small>
      </h1>
    </section>

    <!-- Main content -->
    <section class="content">
      <div id="myTabContent" class="tab-content">
		<!-- 查询面板 -->
		<div class="tab-pane active" id="search">
			<section class="content-header">
			<div class="row">
				<form id="typeForm">
				<input name="pageNo" id="pageNo" type="hidden"/>
				<input name="pageSize" id="pageSize" type="hidden" value="8"/>
				<div class="col-sm-2">
				<input type="text" class="form-control input-lg" id="title"
						name="title" placeholder="标题"></div>
				<div class="col-sm-2">
				<input type="text" class="form-control input-lg" id="cardno"
						name="cardno" placeholder="读者证号"></div>
				<div class="col-sm-2">
					<select	name="isopen" class="form-control" style="padding:inherit;height:45px;">
						<option value="">公开状态</option>
						<option value="0">非公开</option>
						<option value="1">公开</option>
					</select>
				</div>
				<div class="col-sm-2">
					<select	name="isaudit" class="form-control" style="padding:inherit;height:45px;">
						<option value="">审核状态</option>
						<option value="0">未审核</option>
						<option value="1">通过审核</option>
						<option value="2">审核失败</option>
					</select>
				</div>
				</form>
				<div class="col-sm-2">
					<button class="btn btn-primary input-lg"
						onclick="searchList(1);">查询素材</button>
				</div>
				
				<div class="col-sm-2 " style="float: right;">
					<button class="btn btn-primary input-lg"
						onclick="gotoEdit('');">新增素材</button>
				</div>
			</div>
			</section>
		</div>
	</div>
      <div class="row" style="margin-top:10px;">
        <div class="col-xs-12">

          <div class="box">
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>标题</th>
                  <th>分类</th>
                  <th>所属机构</th>
                  <th>所属用户</th>
                  <th>公开状态</th>
                  <th>审核状态</th>
                  <th>创建时间</th>
                  <th>操作</th>
                </tr>
                </thead>
						<tbody id="list">
						</tbody>
					</table>
				<div class="paging" id="pageInfo"></div>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/bootstrap.js"></script>
<script src="dist/js/app.min.js"></script>
<script src="js/page1.js"></script>
<script type="text/javascript" src="js/layer/layer.js"></script>
<script>
$(document).ready(function() {
	searchList(1);
});
function searchList(pageNo){
	$("#pageNo").val(pageNo);
		$.ajax({
			async : false,
			cache : false,
			type : 'post',
			dataType : "json",
			data : $("#typeForm").serialize(),
			url : 'material/material_list_data' ,// 请求的action路径
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				layer.msg("请求失败！");
			},
			success : function(data) {
				if(data.state=="9003"){
					layer.msg("没有权限！");
					return ;
				}else if(data.state=="9002"){
					layer.msg("请重新登录！");
					top.location.reload();
					return ;
				}
					var list = data.list;
					var strHtml = "";
					var oname = "";
					var aname = "";
					for(var i=0;i<list.length;i++){
						if(list[i].isopen=='1'){
							oname = "已公开";
						}else{
							oname = "未公开";
						}
						if(list[i].isaudit=='1'){
							aname = "已通过";
						}else if(list[i].isaudit=='2'){
							aname = "未通过";
						}else {
							aname = "未审核";
						}
						strHtml +='<tr><td>'+list[i].title+'</td>'+
							'<td>'+list[i].fname+'</td>'+
							'<td>'+list[i].gname+'</td>'+
							'<td>'+list[i].uname+'</td>'+
							'<td>'+oname+'</td>'+
							'<td>'+aname+'</td>'+
							'<td>'+list[i].createdate+'</td>'+
							'<td><a class="btn btn-warning" onclick="gotoEdit('+list[i].id+');" href="javascript:void(0);">修改</a> '+
							'<a class="btn btn-primary" onclick="picList('+list[i].id+');" href="javascript:void(0);">图片</a> '+
							'<a class="btn btn-danger" href="javascript:void(0);"onclick="deleteItem('+list[i].id+')">删除</a></td></tr>';
					}
					if(list.length==0){
						strHtml = "<tr style=\"text-align:center;\"><td colspan=\"8\">找不到素材信息！</td></tr>";
					}
					$("#list").html(strHtml);
					$("#pageInfo").html(pageInfo(data.totalPage,data.pageNumber));
					$("#totalRows").html(data.totalRow);
			}
		});	
}
  function deleteItem(id){
	  layer.confirm('你确定要删除吗?', {
 		  title:'删除',
 		  btn: ['确定','取消'] //按钮
 		}, function(){  
  			$.ajax({
				async : false,
				cache : false,
				type : 'post',
				dataType : "json",
				url : 'material/delete_material?id='+id ,// 请求的action路径
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					layer.msg("请求失败！");
				},
				success : function(data) {
					if(data.state=="9003"){
						layer.msg("没有权限！");
						return ;
					}else if(data.state=="9002"){
						layer.msg("请重新登录！");
						top.location.reload();
						return ;
					}
					if(data){
						layer.msg("删除成功！");
						window.location.reload();
					}else{
						layer.msg("删除失败！");
					}
				}
			});	
 		}, function(){
  		});
  }
  function gotoEdit(id){
	  layer.open({
		  title:'编辑素材信息',
		  type: 2,
		  area: ['450px', '430px'],
		  fixed: false, //不固定
		  //maxmin: true,
		  content: 'material/edit_material?id='+id
		});
  }
  function picList(id){
	  layer.open({
		  title:'编辑素材背景图',
		  type: 2,
		  area: ['100%', '100%'],
		  fixed: false, //不固定
		  //maxmin: true,
		  content: 'material/materialpic?materialid='+id
		});
  }
  function regetlist(){
	  window.location.reload();
  }
</script>
</body>
</html>